package com.bigShen.spring;

import com.bigShen.spring.springBean.entity.UserInfo;

import java.beans.Introspector;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author : lei.shen
 * @date : 2019/2/14
 */
public class TestReflect {

    public static void main(String[] args) {

        Class userClass = UserInfo.class;

        Constructor<UserInfo>[] constructor = userClass.getConstructors();
        try {
            UserInfo info = constructor[0].newInstance(null);
            System.out.println(info);

            //Method writeMethod = Introspector.findMethod(userClass, "setUserName", 1, args);
            Method writeMethod = userClass.getMethod("setUserName", String.class);
            writeMethod.invoke(info, "user111");
            System.out.println(info);


        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }

    }

}
